package com.itjob.scott.servlet;


import java.io.IOException;
import java.util.Date;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.itjob.scott.entity.ChatEntity;
import com.itjob.scott.entity.UserEntity;


/**
 * 保存聊天记录  负责存
 * @author 腾田田
 * com.itjob.scott.servlet.ChatServlet.java
 * 2016-4-12
 */
public class ChatServlet extends HttpServlet {
	private static final long serialVersionUID = -8068087013673651522L;
	
	
	@SuppressWarnings("unchecked")
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		String say      = request.getParameter("say");
		Date sendTime   = new Date();
		UserEntity user = (UserEntity) request.getSession().getAttribute("user");
		String username = user.getUsername();
		
		
		ChatEntity chat = new ChatEntity();
		chat.setUsername(username);
		chat.setSay(say);
		chat.setSendTime(sendTime);
		List<ChatEntity> chats = (List<ChatEntity>) this.getServletContext().getAttribute("chats");
		chats.add(chat);
		
	}

}
